/*
 * @Descripttion:
 * @version:
 * @Author: congsir
 * @Date: 2023-12-19 11:30:59
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-12-25 23:39:17
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import esbuild from 'rollup-plugin-esbuild'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
  base: "./", //配置打包相对路径
  plugins: [
    vue(),
    // 按需引入组件的样式
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    esbuild({
      target: "chrome64",
      loaders: {
        ".vue": "js",
        ".ts": "js",
      },
    }),
    legacy({
      targets: ['Chrome 64'],
      modernPolyfills: true
    }),
    //  '@babel/plugin-proposal-optional-chaining',
    //  '@babel/plugin-proposal-nullish-coalescing-operator',
    // '@babel/plugin-proposal-object-rest-spread',
    // '@babel/plugin-transform-runtime',
    
  ],
  presets: ['@vue/cli-plugin-babel/preset','@babel/preset-env',],
 

  server: {
    host: "0.0.0.0", //配置网络服务
    port: 9100, //配置启动端口号
    https: false, // 是否开启 https
    open: true, //自动打开链接
    hot: true, //自动保存
    hmr: true, // 热更新
    strictPort: false, //设为 true 时若端口已被占用则会直接退出，而不是尝试下一个可用端口
    // proxy: {
    //   "/api": {
    //     target: "http://localhost:3001", // 后台地址
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/api/, ""),
    //   },
    // },
  },
  build: {
    assetsPublicPath: "./",
    chunkSizeWarningLimit: 1500, //配置打包块大小
    outDir: "h5", //配置打包文件夹名称
    assetsDir: "static", // 默认为 assets
    minify: 'terser',
    target: ['ios11','edge90', 'chrome90', 'firefox90', 'safari15','Chrome 64','ios12.5.7'], // 适配低版本浏览器

  },
  css: {
    // css预处理器
    preprocessorOptions: {
      less: {
        charset: false,
        additionalData: '@import "./src/assets/css/global.less";',
      },
    },
  },
});
